package org.pms.servlet.administrators;

import org.pms.dao.impl.AdministratorsDaoImplC3P0;
import org.pms.entity.Administrators;
import org.pms.servlet.BaseServlet;
import org.pms.vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 添加管理员
 * @Date 2023-03-01
 * @Author 祝世栩
 */
@WebServlet("/administrators/Insert.do")
public class Insert extends BaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取浏览器传递过来的数据
        String AdministratorsNumber = req.getParameter("administratorsNumber");
        String AdministratorsPwd = req.getParameter("administratorsPwd");
        Administrators administrators = new Administrators();
        administrators.setAdministratorsNumber(AdministratorsNumber);
        administrators.setAdministratorsPwd(AdministratorsPwd);

        int row = new AdministratorsDaoImplC3P0().AdministratorsInsert(administrators);

        // 把处理的数据封装到统一的接口中
        if (row==1){
            ResponseData responseData = successJson(200,"添加成功","") ;
            // System.out.println(responseData);
            print(resp,responseData);
            return;
        }
        print(resp,successJson(500,"添加失败",""));
    }
}
